<?php
namespace app\member\controller;

use app\BaseController;
use app\member\service\TestService;
use app\member\service\TopicService;

class Test extends BaseController
{
    public function test()
    {
        return view();
    }

    public function listTest(){
        try{
            $service = new TestService();
            $page = request()->get('page');
            $limit = request()->get('limit');
            $res = $service->list($page, $limit);
            return json($res);
        }catch (\Throwable $ex){
            return json(AjaxReturn(-1, '操作失败,错误信息:' . $ex->getMessage()));
        }
    }

    public function addTest(){
        try{
            $data = request()->post();
            $service = new TestService();
            $res = $service->add($data);
            return json($res);
        }catch (\Throwable $ex){
            return json(AjaxReturn(-1, '操作失败,错误信息:' . $ex->getMessage()));
        }
    }

    public function editTest(){
        try{
            $data = request()->post();
            $service = new TestService();
            $res = $service->edit($data);
            return json($res);
        }catch (\Throwable $ex){
            return json(AjaxReturn(-1, '操作失败,错误信息:' . $ex->getMessage()));
        }
    }

    public function softdeleteTest(){
        try{
            $ids = request()->post('ids');
            $service = new TestService();
            $res = $service->softdelete($ids);
            return json($res);
        }catch (\Throwable $ex){
            return json(AjaxReturn(-1, '操作失败,错误信息:' . $ex->getMessage()));
        }
    }


    public function topic(){
        return view();
    }

    public function listTopic(){
        try{
            $service = new TopicService();
            $page = request()->get('page');
            $limit = request()->get('limit');
            $res = $service->list($page, $limit);
            return json($res);
        }catch (\Throwable $ex){
            return json(AjaxReturn(-1, '操作失败,错误信息:' . $ex->getMessage()));
        }
    }

    public function addTopic(){
        try{
            $data = request()->post();
            $service = new TopicService();
            $res = $service->add($data);
            return json($res);
        }catch (\Throwable $ex){
            return json(AjaxReturn(-1, '操作失败,错误信息:' . $ex->getMessage()));
        }
    }

    public function editTopic(){
        try{
            $data = request()->post();
            $service = new TopicService();
            $res = $service->edit($data);
            return json($res);
        }catch (\Throwable $ex){
            return json(AjaxReturn(-1, '操作失败,错误信息:' . $ex->getMessage()));
        }
    }

    public function softdeleteTopic(){
        try{
            $ids = request()->post('ids');
            $service = new TopicService();
            $res = $service->softdelete($ids);
            return json($res);
        }catch (\Throwable $ex){
            return json(AjaxReturn(-1, '操作失败,错误信息:' . $ex->getMessage()));
        }
    }

    public function listAllTest(){
        try{
            $service = new TestService();
            $res = $service->listAll();
            return json($res);
        }catch (\Throwable $ex){
            return json(AjaxReturn(-1, '操作失败,错误信息:' . $ex->getMessage()));
        }
    }




}